if ( car.price <= 8000 ) System.out.println("Affordable"); else System.out.println("Too Expensive!");
Augustus De Morgan was a nineteenth century British mathematician
who showed the importance of several rules of logic.
Two of these,
!(A && B)
is equivalent to!A || !B
!(A || B)
is equivalent to!A && !B
These rules are very useful, and worth your time to memorize. This truth table shows why the first rule is true.
A | B | (A && B) | !(A && B) | !A | !B | !A || !B |
---|---|---|---|---|---|---|
F | F | F | T | T | T | T |
F | T | F | T | T | F | T |
T | F | F | T | F | T | T |
T | T | T | F | F | F | F |
The fourth column and the last column have the same truth values. This shows the the expressions at the head of those columns are equivalent.
Rewrite the following fragment (from a previous example):
boolean reject = !(speed > 2000 && memory > 512)